package com.spic.system.controller;

import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.system.domain.UserAllDirty;
import com.spic.system.service.IUserAllDirtyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 人员脏数据Controller
 *
 * @author 赵祥
 * @date 2022-11-24
 */
@RestController
@RequestMapping("/user/dirty")
public class UserAllDirtyController extends BaseController {
    @Autowired
    private IUserAllDirtyService userAllDirtyService;

    /**
     * 查询人员脏数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UserAllDirty userAllDirty) {
        startPage();
        List<UserAllDirty> list = userAllDirtyService.selectUserAllDirtyList(userAllDirty);
        return getDataTable(list);
    }

    @GetMapping("/statistics")
    public AjaxResult statistics() {
        Map<String, Integer> map = userAllDirtyService.statistics();
        return AjaxResult.success(map);
    }

    /**
     * 获取人员脏数据详细信息
     */
    @GetMapping(value = "/{personnelCode}")
    public AjaxResult getInfo(@PathVariable("personnelCode") String personnelCode) {
        return AjaxResult.success(userAllDirtyService.selectUserAllDirtyByPersonnelCode(personnelCode));
    }

    /**
     * 新增人员脏数据
     */
    @PostMapping
    public AjaxResult add(@RequestBody UserAllDirty userAllDirty) {
        return toAjax(userAllDirtyService.insertUserAllDirty(userAllDirty));
    }

    /**
     * 修改人员脏数据
     */
    @PutMapping
    public AjaxResult edit(@RequestBody UserAllDirty userAllDirty) {
        return toAjax(userAllDirtyService.updateUserAllDirty(userAllDirty));
    }

    /**
     * 删除人员脏数据
     */
    @DeleteMapping("/{personnelCodes}")
    public AjaxResult remove(@PathVariable String[] personnelCodes) {
        return toAjax(userAllDirtyService.deleteUserAllDirtyByPersonnelCodes(personnelCodes));
    }
}
